package com.phoenix.fly2.rpc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.shforce.fly2.annotation.RemoteMethod;
import com.shforce.fly2.annotation.RequestScoped;
import com.shforce.fly2.web.WebException;
import org.springframework.stereotype.Component;


@Component("rpc")
public class RpcRemote {


	@RemoteMethod
	public GridDataModel<Map<String,Object>> list(Map<String, ?> map){
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		int limit = (Integer)map.get("limit");
		Map<String,Object> m;
		for(int i = 0 ;i < 30;i++){
			m = new HashMap<String, Object>();
			m.put("state", "state"+(i+1));
			m.put("code", "code"+(i+1));
			list.add(m);
		}
		GridDataModel<Map<String,Object>> grid = new GridDataModel<Map<String,Object>>();
		grid.setRows(list);
		grid.setTotal(10);
		return grid;
	}

	@RemoteMethod
	public String call(String msg) throws WebException {
		if(msg.equals("1")){
			throw new  RuntimeException("111");
		}
		if(msg.equals("2")){
			throw new  WebException("222");
		}
		return ">>"+msg;
	}
}
